﻿using Godot.Collections;
using System;

public class FluidData
{
    public String name;
    public float amount;
    public float max;
    public FluidData(String name, float amount, float max)
    {
        this.name = name;
        this.amount = amount;
        this.max = max;
    }
    public float GetLastAmount()
    {
        return max-amount;
    }
    public bool SubAmount(float amount)
    {
        if (this.amount >= amount)
        {
            this.amount -= amount;
            return true;
        }
        return false;
    }
    public bool AddAmount(float amount)
    {
        if (this.amount < max)
        {
            this.amount += amount;
            if (this.amount > max)
            {
                this.amount = max;
            }
            return true;
        }
        return false;
    }
    public String ToString(String unit)
    {
        return $"{(int)amount}{unit}\n{max}{unit}";
    }
    public float GetPercentage()
    {
        return (float)amount / (float)max;
    }
    public Dictionary GetDictionary()
    {
        Dictionary dic = new Dictionary
        {
            { "name", name },
            { "amount", amount },
            { "max", max }
        };
        return dic;
    }
    public FluidData Parse(Dictionary dict)
    {
        name = (string)dict["name"];
        amount = dict["amount"].ToInt();
        max = dict["max"].ToInt();

        return this;
    }
}
